package com.zhongyouyun.admin.service.imp;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyouyun.admin.mapper.AnalysisMapper;
import com.zhongyouyun.admin.pojo.AnalysisPojo;
import com.zhongyouyun.admin.service.AnalysisService;
import com.zhongyouyun.utils.DateUtils;
import com.zhongyouyun.utils.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;


@Service
@Transactional(rollbackFor = Exception.class)
public class AnalysisServiceImpl extends ServiceImpl<AnalysisMapper, AnalysisPojo> implements AnalysisService {
//    @Override
//    public List<AnalysisPojo> findUserStateAnalysis() {
//        return this.baseMapper.findUserStateAnalysis();
//    }

    @Override
    public List<Map<String,Integer>> findUserStateAnalysisbyDept(Long deptId,int state) {
        List<Map<String,Integer>> reMap=new ArrayList<Map<String,Integer>>();
        Map<String,Integer>  STATE=  new HashMap<String,Integer>();
        STATE.put("STATE",0);
        Map<String,Integer>  NSTATE=  new HashMap<String,Integer>();
        NSTATE.put("NSTATE",0);
        Map<String,Integer>  activation=  new HashMap<String,Integer>();
        activation.put("ACTIVATION",0);
        Map<String,Integer>  NACTIVATION=  new HashMap<String,Integer>();
        NACTIVATION.put("NACTIVATION",0);
        reMap.add(STATE);
        reMap.add(NSTATE);
        reMap.add(activation);
        reMap.add(NACTIVATION);
        List<AnalysisPojo> list= this.baseMapper.findUserStateAnalysisbyDept(deptId, state);
        Map<String,String> map = list.stream().collect(Collectors.toMap(AnalysisPojo::getName,AnalysisPojo::getSa));
        reMap= MapUtils.compareMapHit(reMap,  map);
        return reMap;
    }
//    @Override
//    public Map<String, Object> findHomeCensus() {
//        SimpleDateFormat fmt = new SimpleDateFormat("yyyy");
//        String year = fmt.format(new Date());
//        HashMap<String, Object> returnMap = new HashMap<String, Object>();
//        List<HashMap<Object, Object>> dayMapss = DateUtils.getDay(30);
//        List<HashMap<Object, Object>> dayMaps = DateUtils.getDay(30);
//        List<HashMap<Object, Object>> yearMaps = DateUtils.getYearList(year);
//        List<HashMap<Object, Object>> fileCountShu = this.baseMapper.fileCountShu();
//        List<HashMap<Object, Object>> certificatesCountShu = this.baseMapper.certificatesCountShu();
//        List<HashMap<Object, Object>> invoicesCountShu = this.baseMapper.invoicesCountShu();
//        List<HashMap<Object, Object>> filecount = MapUtils.compareListNullHitData(dayMapss, fileCountShu, "date");//处理文件数据
//        List<HashMap<Object, Object>> certificatesCount = MapUtils.compareListNullHitData(dayMaps, certificatesCountShu, "date");//处理证件数据
//        List<HashMap<Object, Object>> invoicesCount = MapUtils.compareListHitData(yearMaps, invoicesCountShu, "date");//处理发票数据
//        returnMap.put("filecount", filecount);
//        returnMap.put("certificatesCount", certificatesCount);
//        returnMap.put("invoicesCountShu", invoicesCount);
//        return returnMap;
//    }




}
